package composite

import "fmt"

type tCompositeCourse struct {
	tSimpleCourse

	mCourseList []ICourse
	iCourseIndex int
}


func NewCompositeCourse(id int, name string, price float64) ICompositeCourse {
	return &tCompositeCourse {
		tSimpleCourse: tSimpleCourse{
			id, name, price, nil,
		},
		mCourseList: make([]ICourse, 0),
		iCourseIndex: 0,
	}
}

func (me *tCompositeCourse) Append(course ICourse) {
	me.mCourseList = append(me.mCourseList, course)
}

func (me *tCompositeCourse) Learn() LearningStates {
	if me.IsDone() {
		fmt.Printf("%s is learning %s: no more courses\n", me.mUser.Name(), me.Name())
		return DONE
	}


	course := me.mCourseList[me.iCourseIndex]
	fmt.Printf("%s is learning %s.%s\n", me.mUser.Name(), me.Name(), course.Name())
	me.iCourseIndex++

	if me.IsDone() {
		return DONE
	} else {
		return MORE
	}
}

func (me *tCompositeCourse) IsDone() bool {
	return me.iCourseIndex >= len(me.mCourseList)
}